

// NodeJS 链接 MongoDB 数据库 
// Mongoose 连接数据库 
// Mongoose是在node.js环境下对mongodb进行便捷操作的对象模型工具
const mongoose = require('mongoose')


const hostname = "212.129.152.33"
const port = 27017
const dbname = "Desk"
const user = "?"
const pwd = "?"

const CONN_DB_URL = `mongodb://${hostname}:${port}/${dbname}`
// const CONN_DB_URL = `mongodb://${user}:${pwd}@${hostname}:${port}/${dbname}`


mongoose.connect(CONN_DB_URL,(err)=>{
    if(err){
        console.log("数据库链接失败-fail")
    }else{
        console.log("数据库链接成功-success")
    }
})

const connection = mongoose.connection;

connection.on("open",()=>{
    console.log("开始打开数据库链接")
})

connection.on("connected",()=>{
    console.log("connected - 已经链接数据库了")
})

connection.on("disconnected",()=>{
    console.log("disconnected - 数据库断开链接了")
})

connection.on("error",(err)=>{
    console.log("数据库异常了---"+err)
})